package com.glorysoft.sunnypda.bindingadapter

import android.graphics.Color
import android.graphics.drawable.Drawable
import android.provider.CalendarContract
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import androidx.databinding.BindingAdapter

/**
 * FileName: TabIndexGridAdapter
 * Author: XJH
 * Date: 2021/5/13 17:46
 * Description:
 * History:
 */
object StateAdapter {

    @BindingAdapter(value = ["stateBg"], requireAll = false)
    @JvmStatic
    fun setStateBg(textView: TextView, state: String?) {
        if (state == null){
            return
        }

        when(state){
            "Run" -> textView.setTextColor(Color.GREEN)
            "Idle" -> textView.setTextColor(Color.YELLOW)
            "Alarm" -> textView.setTextColor(Color.RED)
            "Disconnected" -> textView.setTextColor(Color.GRAY)
            else ->{
                textView.setTextColor(Color.BLACK)
            }
        }
    }

    @BindingAdapter(value = ["reminder"], requireAll = false)
    @JvmStatic
    fun setReminder(textView: TextView, state: Int?) {
        if (2 == state){
            textView.visibility = View.GONE
        }else{
            textView.visibility = View.VISIBLE
        }
    }

    @BindingAdapter(value = ["state"], requireAll = false)
    @JvmStatic
    fun setState(textView: TextView, state: String?) {
        if ("有效" == state){
            textView.visibility = View.VISIBLE
        }else{
            textView.visibility = View.GONE
        }
    }

    @BindingAdapter(value = ["isSelector"], requireAll = false)
    @JvmStatic
    fun setSelector(ll: LinearLayout, state: Boolean?) {
        if (state == true){
            ll.setBackgroundColor(Color.RED)
        }else{
            ll.setBackgroundColor(Color.WHITE)
        }
    }

    @BindingAdapter(value = ["deletegone"], requireAll = false)
    @JvmStatic
    fun setdeleteGone(textView: TextView, isGone: Boolean?) {
        if (isGone == true){
            textView.visibility = View.INVISIBLE
        }else{
            textView.visibility = View.VISIBLE
        }
    }

    @BindingAdapter(value = ["type"], requireAll = false)
    @JvmStatic
    fun setType(textView: TextView, type: String) {
        textView.text = if (type == "0")"" else type
    }

}